package com.cml.getway.core.helper;

import com.cml.getway.common.enums.ResponseCode;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.http.*;

/**
 * 姓名：陈茂林
 * 时间：2023/12/29
 * 描述：
 */
public class ResponseHelper {
    public static FullHttpResponse getHttpResponse(ResponseCode responseCode) {
        //	TODO: 目前还没有response对象, 我希望自己去创建出一个RapidResponse
        String errorContent = "响应内部错误";
        DefaultFullHttpResponse httpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
                HttpResponseStatus.INTERNAL_SERVER_ERROR,
                Unpooled.wrappedBuffer(errorContent.getBytes()));

        httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, HttpHeaderValues.APPLICATION_JSON + ";charset=utf-8");
        httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, errorContent.length());
        return httpResponse;
    }
}
